﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:cmdr.WpfControls.CustomListBox">

    <ControlTemplate x:Key="customListBoxTemplate" TargetType="{x:Type local:CustomListBox}">
        <ControlTemplate.Resources>
            <Style TargetType="Separator">
                <Setter Property="Background" Value="#FFE3E3E3"/>
                <Setter Property="Margin" Value="0,2,0,2"/>
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Separator}">
                            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                                    BorderThickness="{TemplateBinding BorderThickness}" 
                                    Background="{TemplateBinding Background}" 
                                    Height="1" 
                                    SnapsToDevicePixels="true"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ControlTemplate.Resources>
        <Border Name="Border"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                CornerRadius="2">
            <ScrollViewer x:Name="PART_SV" Margin="0" Focusable="false">
                <StackPanel Margin="2" IsItemsHost="True" />
            </ScrollViewer>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="false">
                <Setter TargetName="Border" Property="Background">
                    <Setter.Value>
                        <SolidColorBrush Color="#FFF4F4F4" />
                    </Setter.Value>
                </Setter>
                <Setter TargetName="Border" Property="BorderBrush">
                    <Setter.Value>
                        <SolidColorBrush Color="#FFF4F4F4" />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="customListBoxItemContainerStyle" TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border x:Name="outerBorder" SnapsToDevicePixels="true">
                        <Border.Background>
                            <SolidColorBrush Color="Transparent" />
                        </Border.Background>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected" />
                                
                                <!-- Exclude separator from selection. -->
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetName="innerBorder" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                            <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource Cmdr.HighlightColor}" />
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                
                                <!-- Exclude separator from selection. -->
                                <VisualState x:Name="SelectedUnfocused">
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetName="innerBorder" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                            <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource Cmdr.HighlightColor}" />
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <StackPanel>
                            <Separator x:Name="Separator" Margin="0" />
                            
                            <!-- Exclude separator from selection. -->
                            <Border x:Name="innerBorder" Padding="2" BorderThickness="0">
                                <Border.Background>
                                    <SolidColorBrush Color="Transparent" />
                                </Border.Background>
                                <ContentPresenter/>
                            </Border>
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                            <Setter Property="Visibility" TargetName="Separator" Value="Collapsed"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</ResourceDictionary>